package com.wuzheng.wisgo.sanitation.cloud.controller.tbox;


import com.wuzheng.wisgo.sanitation.cloud.repository.entity.tbox.ReceiveInfo;
import com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoAllObjectDto;
import com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoToVehicleVo;
import com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveSelectVehAllDto;
import com.wuzheng.wisgo.sanitation.cloud.service.tbox.ReceiveInfoService;
import com.wuzheng.wisgo.sanitation.framework.base.controller.BaseController;
import com.wuzheng.wisgo.sanitation.framework.core.constant.SysRespEnum;
import com.wuzheng.wisgo.sanitation.framework.core.protocol.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author：sp
 * @date：Created in 2019-10-10
 * @description：T-Box数据接受表(所有数据)控制器
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("/receiveInfo")
@Api(value = "ReceiveInfoCtrl", tags = "T-Box数据接受表(所有数据)接口")
public class ReceiveInfoCtrl extends BaseController {

    @Autowired
    private ReceiveInfoService receiveInfoService;



    /**
     * 轨迹回放，搜索框查询车牌号
     */
    @PostMapping(value = "/selectVehCode")
    @ApiOperation(value = "轨迹回放中搜索框查询车牌号")
    public Result<List<ReceiveInfoToVehicleVo>> selectVehCode(@RequestBody  ReceiveInfoToVehicleVo receiveInfoToVehicleVo,
                                                              BindingResult bindingResult) throws BindException {
        if (bindingResult.hasErrors()) {
            throw new BindException(bindingResult);
        }
        return this.success(SysRespEnum.SUCCESS.getMessage(),receiveInfoService.selectVehCodeToVehicle(receiveInfoToVehicleVo));
    }

    /**
     * 轨迹回放，搜索框查询车牌号
     */
    @PostMapping(value = "/selectVehInfo")
    @ApiOperation(value = "轨迹回放车辆详情信息查询")
    public Result<ReceiveSelectVehAllDto> selectVehInfo(@RequestBody @Validated ReceiveInfoToVehicleVo receiveInfoToVehicleVo,
                                                        BindingResult bindingResult) throws BindException {
        if (bindingResult.hasErrors()) {
            throw new BindException(bindingResult);
        }
        return this.success(SysRespEnum.SUCCESS.getMessage(),receiveInfoService.receiveSelectVehInfo(receiveInfoToVehicleVo));
    }

    /**
     * 轨迹回放，搜索框查询车牌号
     */
    @PostMapping(value = "/selectLongLatInfo")
    @ApiOperation(value = "轨迹回放点信息查询")
    public Result<ReceiveInfoAllObjectDto> selectLongLatInfo(@RequestBody @Validated ReceiveInfoToVehicleVo receiveInfoToVehicleVo,
                                                             BindingResult bindingResult) throws BindException {
        if (bindingResult.hasErrors()) {
            throw new BindException(bindingResult);
        }
        return this.success(SysRespEnum.SUCCESS.getMessage(),receiveInfoService.selectLongLatAllFromReceice(receiveInfoToVehicleVo));
    }


    /**
     * 获取T-Box数据接受表(所有数据)列表
     */
    @PostMapping(value = "/list")
    @ApiOperation(value = "获取T-Box数据接受表(所有数据)列表")
    public Result<List<ReceiveInfo>> list() {
        return this.success(receiveInfoService.selectList());
    }

    /**
     * 获取T-Box数据接受表(所有数据)列表
     */
    @PostMapping(value = "/getAddressByPoint")
    @ApiOperation(value = "数据转换")
    public Result<List<ReceiveInfo>> getAddressByPoint(@RequestBody String vehId,String mapType) throws Exception {
        receiveInfoService.getAddressByPoint(vehId,mapType);
        return this.success(SysRespEnum.SUCCESS.getMessage());
    }

//    =============================================================================================
//    =========T-Box数据接受表不需要增删改，只需要查询数据，所以暂时注释掉，如果后期需要再打开注释
//    =========sunpeng  2019/10/10
//    =============================================================================================
//    /**
//     * 新增T-Box数据接受表(所有数据)
//     */
//    @PostMapping(value = "/add")
//    @ApiOperation(value = "新增T-Box数据接受表(所有数据)")
//    public Result<String> add(ReceiveInfo tbox) {
//        receiveInfoService.insert(tbox);
//        return this.success();
//    }
//
//    /**
//     * 删除T-Box数据接受表(所有数据)
//     */
//    @PostMapping(value = "/delete/{id}")
//    @ApiOperation(value = "删除T-Box数据接受表(所有数据)")
//    public Result<String> delete(@PathVariable("id") Long id) {
//        receiveInfoService.deleteById(id);
//        return this.success();
//    }
//
//    /**
//     * 修改T-Box数据接受表(所有数据)
//     */
//    @PostMapping(value = "/update")
//    @ApiOperation(value = "修改T-Box数据接受表(所有数据)")
//    public Result<String> update(ReceiveInfo tbox) {
//        receiveInfoService.updateById(tbox);
//        return this.success();
//    }
//
//    /**
//     * 获取T-Box数据接受表(所有数据)
//     */
//    @GetMapping(value = "/get/{id}")
//    @ApiOperation(value = "获取T-Box数据接受表(所有数据)")
//    public Result<ReceiveInfo> get(@PathVariable("id") Long id) {
//        return this.success(receiveInfoService.selectById(id));
//    }


}

